package com.hundsun.network.uc.common;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

/**
 * 网络请求
 * Created by zhengkk19738 on 2018/4/28.
 */
public class RestTemplateUtil {

    private RestTemplateUtil() {

    }


    public static Map requestHttp(String url, Map<String, String> paramMap) {
        //设置header
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Content-Type", "application/json; charset=UTF-8");

        HttpEntity<Map<String, String>> requestEntity = new HttpEntity<Map<String, String>>(paramMap, httpHeaders);

        //执行请求
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<Map> resp = restTemplate.exchange(url, HttpMethod.POST, requestEntity, Map.class);

        //获取返回的header
        List<String> val = resp.getHeaders().get("Set-Cookie");
        System.out.println(val);

        //获得返回值
        Map responseBody = resp.getBody();

        return responseBody;

    }


}
